//
//  AppDelegate.m
//  新项目
//
//  Created by 刘耀宗 on 2016/10/21.
//  Copyright © 2016年 刘耀宗. All rights reserved.
//

#import "AppDelegate.h"
#import "YGKJTabbarVC.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

//添加自定义3D_Touch
- (void)addCustomQuickActionsItem{
    
    //3D Touch按压程序图标的快捷项
    //快捷菜单的图标
    UIApplicationShortcutIcon *icon2=[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
    UIApplicationShortcutIcon *icon1=[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeShare];
    //快捷菜单
    UIApplicationShortcutItem *item1=[[UIApplicationShortcutItem alloc]initWithType:@"1"
                                                                     localizedTitle:@"不知道去哪里"
                                                                  localizedSubtitle:nil
                                                                               icon:icon2
                                                                           userInfo:nil];
    
    
    UIApplicationShortcutItem *item2=[[UIApplicationShortcutItem alloc]initWithType:@"1"
                                                                     localizedTitle:@"还是不知道去哪里"
                                                                  localizedSubtitle:nil
                                                                               icon:icon2
                                                                           userInfo:nil];
    
    
    [[UIApplication sharedApplication] setShortcutItems:@[item1,item2]];
    
}



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 3d touch
     [self addCustomQuickActionsItem];
    
    //初始化键盘
    [self initKeyBoard];
    //注册通知
    [self YuanChengTuiSong:application];
    
    
    UIWindow *window=[[UIWindow alloc] initWithFrame:CGRectMake(0, 0, newwidth, newheight)];
    self.window=window;
    YGKJTabbarVC *tabbarVC=[[YGKJTabbarVC alloc] init];
    self.window.rootViewController=tabbarVC;
    [self.window makeKeyAndVisible];
    

    
    
    return YES;
}

#pragma mark---键盘初始化
-(void)initKeyBoard
{
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = YES;
    manager.shouldResignOnTouchOutside = YES;
    manager.shouldToolbarUsesTextFieldTintColor = YES;
    manager.enableAutoToolbar = NO;
}
#pragma mark---注册远程推送
-(void)YuanChengTuiSong:(UIApplication *)application
{
    if ([UIDevice currentDevice].systemVersion.doubleValue>=8.0) {
        //      注册通知权限
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil];
        [application registerUserNotificationSettings:settings];
        
        //注册远程推送通知(这才是和苹果的远程推送服务器进行连接)
        [application registerForRemoteNotifications];

    }else
    {
        //  iOS7这么设置
        //  如果是iOS8： Please use registerForRemoteNotifications and registerUserNotificationSettings: instead
        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
    }


}

//注册远程通知后获取DeviceToken
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    //极光
    NSString *deviceTokenStr = [NSString stringWithFormat:@"%@",deviceToken];
    deviceTokenStr = [[deviceTokenStr substringWithRange:NSMakeRange(0, 72)] substringWithRange:NSMakeRange(1, 71)];
    //将deviceToken保存在NSUserDefaults
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //保存 device token 令牌,并且去掉空格
    [userDefaults setObject:[deviceTokenStr stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"deviceToken"];
}

- (void)applicationWillResignActive:(UIApplication *)application {
 
}

// APP进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application
{
   }

// APP将要从后台返回
- (void)applicationWillEnterForeground:(UIApplication *)application
{
   }

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
